<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>记账系统 - 当月统计</title>
<!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/d3.v3.min.js"></script>
<script src="libs/nv.d3.min.css"></script>
<script src="libs/nv.d3.min.js"></script>
</head>
<body>

	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>记账</strong>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-8">
				<ul class="nav nav-pills">
					<li><a href="#">用户： <span id="text3"></span>
					</a></li>

					<li><a href="index.html">首页</a></li>
					<li><a href="xjsr.html">新加收入</a></li>
					<li><a href="xjzc.html">新加支出</a></li>
					<li class="active"><a href="month.html">当月统计</a></li>
					<li><a href="queryall.html">查询</a></li>
				</ul>
			</div>
		</div>
	</div>


	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<hr />
			</div>
		</div>
	</div>

	<div class="col-md-6">
		<div class="panel panel-warning">
			<div class="panel-heading">当月收入总和</div>
			<div class="panel-body" id="text1"></div>
		</div>
	</div>

	<div class="col-md-6">
		<div class="panel panel-warning">
			<div class="panel-heading">当月支出总和</div>
			<div class="panel-body" id="text2"></div>
		</div>
	</div>

	<div class="col-md-12">
		<div class="panel panel-primary">
			<div class="panel-heading">类别收入记录</div>
			<div class="panel-body" id="list1"></div>
		</div>
	</div>

	<div class="col-md-12">
		<div class="panel panel-success">
			<div class="panel-heading">类别支出记录</div>
			<div class="panel-body" id="list2"></div>
		</div>
	</div>

	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<div class="col-md-6" id="chart">
					<p class="text-center">
						<br />
					<hr />
					<strong>收入使用统计</strong>
					<svg style="height: 480px; width: 100%"></svg>
					<br />
					</p>
				</div>

				<div class="container">
					<div class="row">
						<div class="col-md-6" id="chart2">
							<p class="text-center">
								<br />
							<hr />
							<strong>支出使用统计</strong>
							<svg style="height: 480px; width: 100%"></svg>
							<br />
							</p>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>


	<script type="text/javascript">
		$(function() {
			$.getJSON('query_monthin.action', function(res) {
				console.log(res);
				$('#text1').text(res.min);
			});
			$.getJSON('query_monthout.action', function(res) {
				console.log(res);
				$('#text2').text(res.mout);

			});
			$.getJSON('query_nickname.action', function(res) {
				console.log(res);
				$('#text3').text(res.nickname);

			});

			$.getJSON('query_avgin.action', function(res) {
				console.log(res);
				var data = {
					'item' : res
				};
				var t = Handlebars.compile($('#template').html());

				$('#list1').html(t(data));

			});
			$.getJSON('query_avgout.action', function(res) {
				console.log(res);
				//res存在 json里  再把res存在item（json）里面  
				var data = {
					'item' : res
				};
				//调用Handlebars里面compile的这个方法，把 template 显示出来
				var t = Handlebars.compile($('#template2').html());
				//必须需要 这样的形式 ：[{"fm":"300"},{"fm":"400"}]  才能显示出来 
				$('#list2').html(t(data));

			});

			$.getJSON('query_avgin.action', function(res) {
				nv.addGraph(function() {
					var chart = nv.models.pieChart().x(function(d) {
						return d.kin
					}).y(function(d) {
						return d.suin
					}).showLabels(true).labelType('percent');
					d3.select('#chart svg').datum(res).transition().duration(
							350).call(chart);
					return chart;
				});
			});
			$.getJSON('query_avgout.action', function(res) {
				nv.addGraph(function() {
					var chart2 = nv.models.pieChart().x(function(d) {
						return d.kin
					}).y(function(d) {
						return d.suout
					}).showLabels(true).labelType('percent');
					d3.select('#chart2 svg').datum(res).transition().duration(
							350).call(chart2);
					return chart2;
				});
			});

		});
	</script>
	<script type="text/javascript" src="libs/handlebars.min.js"></script>
	<script id="template" type="text/x-handlebars-template">
	{{#each item}}
		<div class="panel panel-default col-md-3">
			<div class="panel-body">
				<dl>
					<dt>总和</dt><dd>{{suin}}</dd>
					<dt>类别</dt><dd>{{kin}}</dd>
					<dt>平均值</dt><dd>{{avgin}}</dd>
				</dl>
			</div>
		</div>
	{{/each}}

	</script>
	<script id="template2" type="text/x-handlebars-template">
	{{#each item}}
		<div class="panel panel-default col-md-3">
			<div class="panel-body">
				<dl>
					<dt>总和</dt><dd>{{suout}}</dd>
					<dt>类别</dt><dd>{{kin}}</dd>
					<dt>平均值</dt><dd>{{avgout}}</dd>
				</dl>
			</div>
		</div>
	{{/each}}

	</script>

</body>
</html>
